const http = require("http");

const Router = require("./router");

function Application() {
  // 每个应用都配置一个路由表
  this.router = new Router();
}
Application.prototype.get = function (path, ...handlers) {
  this.router.get(path, handlers);
};
Application.prototype.listen = function (...args) {
  const server = http.createServer((req, res) => {
    function done() {
      res.end(`my Cannot ${req.method.toLowerCase()} ${req.url}`);
    }
    this.router.handle(req, res, done);
    // done(); // 应用如果发现路由无法处理，那就自己报一个找不到
  });
  server.listen(...args);
};
module.exports = Application;
